<?php

namespace app\client\services;

use app\admin\model\CustomerModel;
use app\admin\model\IncomeModel;

class IncomeService extends \app\admin\services\BaseService
{
    public static function index($p){
        $params=[
            'page'=>($p['pageNo'])??1,
            'pageSize'=>($p['pageSize'])??10,
            'where'=>[
                ['customer_id','=',$p['customer_id']]
            ]
        ];
        if(!empty($p['fromTime'])&&!empty($p['toTime']))
        {
            $params['where'][]=['create_time','>=',$p['fromTime']];
            $params['where'][]=['create_time','<=',$p['to'].' 23:59:59'];
        }
        $list=IncomeModel::getList($params);
        $total=IncomeModel::count($params['where']);
        api_return(200,'',['list'=>$list,'total'=>$total,'balance'=>CustomerModel::find($p['customer_id'])->balance]);
    }
}
